<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>react组件实例的三大属性之State</title>
</head>
<body>
  <!-- 创建一个容器 -->
  <div id="test"></div>

  <!-- 导入react库 -->
  <script type="text/javascript" src="../js/react.development.js"></script>
  <script type="text/javascript" src="../js/react-dom.development.js"></script>
  <script type="text/javascript" src="../js/babel.min.js"></script>

  <script type="text/babel">
    // 创建组件
    class Weather extends React.Component {

      // 初始化状态
      state = { isHot:true, wind:"无风" }

      render() {
        const { isHot,wind } = this.state
        return (
          <div>
            <h2 onClick={this.changeWeather}>今天天气很{isHot ? "炎热" : "凉爽"}, {wind ? "无风" : "微风"}</h2>
          </div>
        )
      }

      // 自定义方法————要使用赋值语句方式 + 箭头函数
      changeWeather = ()=>{
        const isHot = this.state.isHot
        const wind = this.state.wind
        this.setState({ isHot:!isHot, wind:!wind })
      }
    }

    // 渲染组件到页面
    ReactDOM.render(<Weather/>, document.getElementById('test'))

    
  </script>
</body>
</html>